var Adv_skd=require("./Adv_skd")

var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2ADManager = require("ADManager");
var $2AudioManager = require("AudioManager");
var $2UIManager = require("UIManager");
var $2FlbMathUtil = require("FlbMathUtil");
var $2UserDataManager = require("UserDataManager");
var $2kc = require("kc");
var $2pvzChannel = require("pvzChannel");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_PauseUI = /* */function (_cc$Component56) {
  babel_inherits(g, _cc$Component56);
  var _super61 = babel_createSuper(g);
  function g() {
    var _this135;
    babel_classCallCheck(this, g);
    _this135 = _super61.apply(this, arguments);
    _this135.audioPanel = null;
    _this135.effectPanel = null;
    _this135.dhm = null;
    _this135.dhm_val = null;
    _this135.tip = null;
    return _this135;
  }
  babel_createClass(g, [{
    key: "start",
    value: function start() {
      Adv_skd.default.instance.hideAllAdv();
      Adv_skd.default.instance.showInterstitialAd();
      Adv_skd.default.instance.showGridAdRight();
      Adv_skd.default.instance.showGridAdLeft();

      console.log("开始界面")
      this.dhm = cc.find("Panel/Bg/DuihuanmaPanel/dhm", this.node);
      this.tip = cc.find("Panel/Bg/DuihuanmaPanel/tip", this.node);
      this.dhm.on(cc.Node.EventType.TOUCH_START, this.on_dhm, this);
      this.refreshPanel();
      this.initPlatform();
      cc.director.pause();
    }
  }, {
    key: "on_dhm",
    value: function on_dhm() {
      var _this136 = this;
      var e = this.dhm_val.string;
      if (!e || e.length < 2) {
        console.log(e, 6666666);
        return void (this.tip.getComponent(cc.Label).string = "请填写正确的兑换码");
      }
      var t = e.split("");
      for (var a = 0; a < t.length; a++) {
        t[a] = t[a].toUpperCase();
      }
      e = t.join("");
      console.log(e, 5555);
      if ($2kc.default.getData1("code", {})[e]) {
        this.dhm_val.string = "";
        return void (this.tip.getComponent(cc.Label).string = "兑换码已经被使用");
      }
      $2kc.default.jpost("https://ga.gamejym.com/fcm/gameApi/redeem", {
        code: e,
        gameId: "植物大战僵尸2进化",
        userId: "" + $2kc.default.getData1("userId", "unknown")
      }, function (t, a) {
        if (t) {
          return void (_this136.tip.getComponent(cc.Label).string = "兑换失败，请稍后再试.");
        }
        if (-2 === a.code) {
          return void (_this136.tip.getComponent(cc.Label).string = "兑换失败，请稍后再试.");
        }
        console.log(a, t);
        var n = $2kc.default.getData1("code", {});
        n[e] = 1;
        $2kc.default.saveData1("code", n);
        var i = ["喜迎新春", "新年发大财", "植物娘拜年啦", "新春快乐", "恭喜发财"];
        var s = 0;
        for (var _l2 in i) {
          if (i[_l2] === e) {
            s = parseInt(_l2);
            break;
          }
        }
        var o = 1;
        switch (s) {
          case 0:
            o = $2FlbMathUtil.MathUtil.getRandomInt(11, 20);
            $2UserDataManager.default.instance.setPlantChip(o, 10);
            break;
          case 1:
            o = $2FlbMathUtil.MathUtil.getRandomInt(11, 20);
            $2UserDataManager.default.instance.setPlantChip(o, 15);
            break;
          case 2:
            $2UserDataManager.default.instance.diamond += 400;
            $2UserDataManager.default.instance.gold += 5e3;
            break;
          case 3:
            $2UserDataManager.default.instance.gold += 5e3;
            break;
          case 4:
            o = $2FlbMathUtil.MathUtil.getRandomInt(11, 20);
            $2UserDataManager.default.instance.setPlantChip(o, 5);
            $2UserDataManager.default.instance.diamond += 300;
        }
        _this136.tip.getComponent(cc.Label).string = ["随机植物碎片:10", "随机植物碎片:15", "钻石:400,金币:5000", "金币:5000", "随机植物碎片:5;钻石:300"][s];
      });
    }
  }, {
    key: "refreshPanel",
    value: function refreshPanel() {

      if ($2AudioManager.default.instance.muteBgm) {
        this.audioPanel.getChildByName("Open").children[0].active = false;
        this.audioPanel.getChildByName("Close").children[0].active = true;
      } else {
        this.audioPanel.getChildByName("Open").children[0].active = true;
        this.audioPanel.getChildByName("Close").children[0].active = false;
      }
      if ($2AudioManager.default.instance.muteEffect) {
        this.effectPanel.getChildByName("Open").children[0].active = false;
        this.effectPanel.getChildByName("Close").children[0].active = true;
      } else {
        this.effectPanel.getChildByName("Open").children[0].active = true;
        this.effectPanel.getChildByName("Close").children[0].active = false;
      }
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      switch ($2ADManager.default.instance.sdkType) {
        case $2ADManager.SDK_TYPE.WeChat:
          $2ADManager.default.instance.showNative(2);
          $2ADManager.default.instance.showNative(3);
          $2ADManager.default.instance.showNative(1);
          $2ADManager.default.instance.hideNative(0);
          $2ADManager.default.instance.showBanner();
      }
      "tt" === $2pvzChannel.pvzChannel.instance().channel && $2pvzChannel.pvzChannel.instance().showInter();
    }
  }, {
    key: "onClickOpenMusic",
    value: function onClickOpenMusic() {
      if ($2AudioManager.default.instance.muteBgm) {
        $2AudioManager.default.instance.muteBgm = false;
        $2AudioManager.default.instance.resumeBgm();
        this.refreshPanel();
      }
    }
  }, {
    key: "onClickCloseMusic",
    value: function onClickCloseMusic() {
      if (!$2AudioManager.default.instance.muteBgm) {
        $2AudioManager.default.instance.pauseBgm();
        $2AudioManager.default.instance.muteBgm = true;
        this.refreshPanel();
      }
    }
  }, {
    key: "onClickOpenEffect",
    value: function onClickOpenEffect() {
      if ($2AudioManager.default.instance.muteEffect) {
        $2AudioManager.default.instance.muteEffect = false;
        this.refreshPanel();
      }
    }
  }, {
    key: "onClickCloseEffect",
    value: function onClickCloseEffect() {
      if (!$2AudioManager.default.instance.muteEffect) {
        $2AudioManager.default.instance.muteEffect = true;
        this.refreshPanel();
      }
    }
  }, {
    key: "onClickBackHomeBtn1",
    value: function onClickBackHomeBtn1() {
Adv_skd.default.instance.hideAllAdv();

      cc.director.resume();
      $2UIManager.default.instance.closeUI("BowlingUI");
      $2UIManager.default.instance.closeUI("Pause1UI");
      $2UIManager.default.instance.openUI("MenuUI");
    }
  }, {
    key: "onClickRestartBtn",
    value: function onClickRestartBtn() {
Adv_skd.default.instance.hideAllAdv();

      cc.director.resume();
      $2UIManager.default.instance.closeUI("PauseUI");
      $2UIManager.default.instance.closeUI("PrepareCards");
      $2UIManager.default.instance.closeUI("MainUI");
      $2UIManager.default.instance.openUI("MainUI");
    }
  }, {
    key: "onClickBackHomeBtn",
    value: function onClickBackHomeBtn() {
Adv_skd.default.instance.hideAllAdv();

      cc.director.resume();
      $2UIManager.default.instance.closeUI("PauseUI");
      $2UIManager.default.instance.closeUI("PrepareCards");
      $2UIManager.default.instance.closeUI("MainUI");
      $2UIManager.default.instance.openUI("MenuUI");
    }
  }, {
    key: "onClickContinueBtn",
    value: function onClickContinueBtn() {
Adv_skd.default.instance.hideAllAdv();

      cc.director.resume();
      $2UIManager.default.instance.closeUI("PauseUI");
    }
  }, {
    key: "onDestroy",
    value: function onDestroy() {
      $2ADManager.default.instance.hideNative(1);
      $2ADManager.default.instance.hideNative(2);
      $2ADManager.default.instance.hideNative(3);
    }
  }]);
  return g;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_PauseUI.prototype, "audioPanel", undefined);
cc__decorate([ccp_property(cc.Node)], def_PauseUI.prototype, "effectPanel", undefined);
cc__decorate([ccp_property(cc.EditBox)], def_PauseUI.prototype, "dhm_val", undefined);
def_PauseUI = cc__decorate([ccp_ccclass], def_PauseUI);
exports.default = def_PauseUI;